package org.site.group;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.util.groupUtil.groupHibernaterUtil;




@Controller
public class groupController {
	
	
	@RequestMapping("/createGroup")
	public ModelAndView addgroup(HttpServletRequest request,
			HttpServletResponse response, groupBean group) throws Exception {
		System.out.println("stdout - create group");
		Session session = groupHibernaterUtil.getSessionFactory().openSession();
	    session.beginTransaction();
		session.save(group);
		session.getTransaction().commit();
		System.out.println(group.getgroupName());
	    group = (groupBean)session.get(groupBean.class, new Integer(1));
	    request.setAttribute("group", group);
		ModelAndView modelGroup = new ModelAndView("/world/directGroup");
	return modelGroup;
	}
	
	
	@RequestMapping("/start")
	public ModelAndView add() { 	
		System.out.println("stdout - start group");
		ModelAndView modelGroup = new ModelAndView("world/create");
		modelGroup.addObject("group", new groupBean());
		return modelGroup;
	}
	
	@RequestMapping("/group")
	public  ModelAndView  groupDisplay(HttpServletRequest request,
			HttpServletResponse response,groupBean group) {
		System.out.println("stdout - show group");
		Session session = groupHibernaterUtil.getSessionFactory().openSession();
	    session.beginTransaction();
	    group = (groupBean)session.get(groupBean.class, new Integer(1));
	    request.setAttribute("group", group);
		session.getTransaction().commit();
		System.out.println(group.getgroupName());
		ModelAndView modelGroup = new ModelAndView("world/group");
	return modelGroup;
	}

}
